package com.qingdai.business.emuns;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.data.annotation.Id;
import org.springframework.data.elasticsearch.annotations.Document;
import org.springframework.data.elasticsearch.annotations.Field;
import org.springframework.data.elasticsearch.annotations.FieldType;

import java.io.Serializable;

/**
 * <p>
 * 详细地址
 * </p>
 *
 * @author LiuZiMing
 * @since 2024-01-26
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
@TableName("address__address")
@Document(indexName="address")
@Schema(description = "详细地址")
public class Address implements Serializable {

    @TableId(value = "id", type = IdType.AUTO)
    @Id
    @Schema(description = "id")
    private Integer id;

    @TableField("name")
    @Field(type = FieldType.Text)
    @Schema(description = "名称")
    private String name;

    @TableField("province_id")
    @Field(type = FieldType.Integer)
    @Schema(description = "省id")
    private Integer provinceId;

    @TableField("city_id")
    @Field(type = FieldType.Integer)
    @Schema(description = "市id")
    private Integer cityId;

    @TableField("district_id")
    @Field(type = FieldType.Integer)
    @Schema(description = "区id")
    private Integer districtId;

    @TableField("position")
    @Field(type = FieldType.Text)
    @Schema(description = "详细位置")
    private String position;

    @TableField("phone_number")
    @Field(type = FieldType.Long)
    @Schema(description = "手机号")
    private Long phoneNumber;

    @TableField("user_id")
    @Field(type = FieldType.Integer)
    @Schema(description = "创建此地址的用户id")
    private Integer userId;


    public static AddressDTO toDTO(Address address){
        AddressDTO addressDTO = new AddressDTO();
        addressDTO.setId(address.getId());
        addressDTO.setName(address.getName());
        addressDTO.setProvinceId(address.getProvinceId());
        addressDTO.setCityId(address.getCityId());
        addressDTO.setDistrictId(address.getDistrictId());
        addressDTO.setPosition(address.getPosition());
        addressDTO.setPhoneNumber(address.getPhoneNumber());
        addressDTO.setUserId(address.getUserId());
        return addressDTO;
    }
}
